package com.by.service.impl;

import com.by.entity.Supplier;
import com.by.entity.User;
import com.by.entity.UserType;
import com.by.mapper.SupplierMapper;
import com.by.mapper.UsersMapper;
import com.by.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class SupplierServiceImpl implements SupplierService {

    @Autowired
    private UsersMapper usersMapper;
    @Autowired
    private SupplierMapper supplierMapper;

    @Transactional
    @Override
    public int saveSupplier(Supplier supplier) {
        User user = new User(supplier.getAccount(),supplier.getPassword(), UserType.SUPPLIER_USER);

        int ids= usersMapper.saveUser(user);
        if (ids==0){
            return 0;
        }
        supplier.setId(user.getId());
        int sus = supplierMapper.save(supplier);

        return sus;
    }
}
